package com.daigoudao.web.service.impl;

import java.util.List;

import com.daigoudao.web.dao.ISimpleBuyDao;
import com.daigoudao.web.dao.IWantBuyDao;
import com.daigoudao.web.model.SimpleBuyModel;
import com.daigoudao.web.model.WantBuyModel;
import com.daigoudao.web.service.IWantBuyService;

public class WantBuyServiceImpl implements IWantBuyService {

	private IWantBuyDao wantBuyDao;

	private ISimpleBuyDao simpleBuyDao;

	public void setSimpleBuyDao(ISimpleBuyDao simpleBuyDao) {
		this.simpleBuyDao = simpleBuyDao;
	}

	public void setWantBuyDao(IWantBuyDao wantBuyDao) {
		this.wantBuyDao = wantBuyDao;
	}

	@Override
	public void addWantBuy(WantBuyModel wantBuyModel) throws Exception {
		String validityPeriod = wantBuyModel.getValidityPeriod();
		wantBuyModel.setValidityPeriod(validityPeriod + " 59:59:59");
		wantBuyDao.addWantBuy(wantBuyModel);
	}

	@Override
	public int getWantBuyCount(WantBuyModel wantBuyModel) throws Exception {
		return wantBuyDao.getWantBuyCount(wantBuyModel);
	}

	@Override
	public WantBuyModel queryWantBuyDetail(int wantId) throws Exception {
		WantBuyModel wantBuyModel = wantBuyDao.queryWantBuyDetail(wantId);
		SimpleBuyModel query = new SimpleBuyModel();
		query.getWantBuyModel().setWantId(wantBuyModel.getWantId());
		int simpleBuys = simpleBuyDao.getSimpleBuyCount(query);
		wantBuyModel.setSimpleBuys(simpleBuys);
		return wantBuyModel;
	}

	@Override
	public List<WantBuyModel> queryWantBuys(WantBuyModel wantBuyModel)
			throws Exception {
		return wantBuyDao.queryWantBuys(wantBuyModel);
	}

	@Override
	public List<WantBuyModel> queryMyWantBuys(WantBuyModel wantBuyModel)
			throws Exception {
		return wantBuyDao.queryMyWantBuys(wantBuyModel);
	}
	
	@Override
	public List<SimpleBuyModel> queryMySimpleBuys(SimpleBuyModel simpleBuyModel)
			throws Exception {
		return wantBuyDao.queryMySimpleBuys(simpleBuyModel);
	}

	@Override
	public List<WantBuyModel> getNewWantBuyList() throws Exception {
		return wantBuyDao.getNewWantBuyList();
	}

	public List<WantBuyModel> queryOtherWantBuys(WantBuyModel wantBuyModel)
			throws Exception {
		return wantBuyDao.queryOtherWantBuys(wantBuyModel);
	}

	public int getMyWantBuyCount(WantBuyModel wantBuyModel) throws Exception {
		return wantBuyDao.getMyWantBuyCount(wantBuyModel);
	}
	
	public int getMySimpleBuyCount(SimpleBuyModel simpleBuyModel) throws Exception {
		return wantBuyDao.getMySimpleBuyCount(simpleBuyModel);
	}

	public void updateStatus(WantBuyModel wantBuyModel) throws Exception {
		wantBuyDao.updateStatus(wantBuyModel);
	}
	
	public void updateSimpleBuyStatus(SimpleBuyModel simpleBuyModel) throws Exception {
		wantBuyDao.updateSimpleBuyStatus(simpleBuyModel);
	}
	
}
